home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / NOTES < prev    next >
Encoding:
Text File  |  1994-10-26  |  4.4 KB  |  96 lines

  1. Feature Test Macros
  2. -------------------
  3.  
  4.    The exact set of features available when you compile a source file
  5. is controlled by which "feature test macros" you define.
  6.  
  7.    If you compile your programs using `gcc -ansi', you get only the
  8. ANSI C library features, unless you explicitly request additional
  9. features by defining one or more of the feature macros.  *Note GNU CC
  10. Command Options: (gcc.info)Invoking GCC, for more information about GCC
  11. options.
  12.  
  13.    You should define these macros by using `#define' preprocessor
  14. directives at the top of your source code files.  These directives
  15. *must* come before any `#include' of a system header file.  It is best
  16. to make them the very first thing in the file, preceded only by
  17. comments.  You could also use the `-D' option to GCC, but it's better
  18. if you make the source files indicate their own meaning in a
  19. self-contained way.
  20.  
  21.  - Macro: _POSIX_SOURCE
  22.      If you define this macro, then the functionality from the POSIX.1
  23.      standard (IEEE Standard 1003.1) is available, as well as all of the
  24.      ANSI C facilities.
  25.  
  26.  - Macro: _POSIX_C_SOURCE
  27.      If you define this macro with a value of `1', then the
  28.      functionality from the POSIX.1 standard (IEEE Standard 1003.1) is
  29.      made available.  If you define this macro with a value of `2',
  30.      then both the functionality from the POSIX.1 standard and the
  31.      functionality from the POSIX.2 standard (IEEE Standard 1003.2) are
  32.      made available.  This is in addition to the ANSI C facilities.
  33.  
  34.  - Macro: _BSD_SOURCE
  35.      If you define this macro, functionality derived from 4.3 BSD Unix
  36.      is included as well as the ANSI C, POSIX.1, and POSIX.2 material.
  37.  
  38.      Some of the features derived from 4.3 BSD Unix conflict with the
  39.      corresponding features specified by the POSIX.1 standard.  If this
  40.      macro is defined, the 4.3 BSD definitions take precedence over the
  41.      POSIX definitions.
  42.  
  43.      Due to the nature of some of the conflicts between 4.3 BSD and
  44.      POSIX.1, you need to use a special "BSD compatibility library"
  45.      when linking programs compiled for BSD compatibility.  This is
  46.      because some functions must be defined in two different ways, one
  47.      of them in the normal C library, and one of them in the
  48.      compatibility library.  If your program defines `_BSD_SOURCE', you
  49.      must give the option `-lbsd-compat' to the compiler or linker when
  50.      linking the program, to tell it to find functions in this special
  51.      compatibility library before looking for them in the normal C
  52.      library.
  53.  
  54.  - Macro: _SVID_SOURCE
  55.      If you define this macro, functionality derived from SVID is
  56.      included as well as the ANSI C, POSIX.1, and POSIX.2 material.
  57.  
  58.  - Macro: _GNU_SOURCE
  59.      If you define this macro, everything is included: ANSI C, POSIX.1,
  60.      POSIX.2, BSD, SVID, and GNU extensions.  In the cases where POSIX.1
  61.      conflicts with BSD, the POSIX definitions take precedence.
  62.  
  63.      If you want to get the full effect of `_GNU_SOURCE' but make the
  64.      BSD definitions take precedence over the POSIX definitions, use
  65.      this sequence of definitions:
  66.  
  67.           #define _GNU_SOURCE
  68.           #define _BSD_SOURCE
  69.           #define _SVID_SOURCE
  70.  
  71.      Note that if you do this, you must link your program with the BSD
  72.      compatibility library by passing the `-lbsd-compat' option to the
  73.      compiler or linker.  *Note:* If you forget to do this, you may get
  74.      very strange errors at run time.
  75.  
  76.    We recommend you use `_GNU_SOURCE' in new programs.  If you don't
  77. specify the `-ansi' option to GCC and don't define any of these macros
  78. explicitly, the effect is the same as defining `_GNU_SOURCE'.
  79.  
  80.    When you define a feature test macro to request a larger class of
  81. features, it is harmless to define in addition a feature test macro for
  82. a subset of those features.  For example, if you define
  83. `_POSIX_C_SOURCE', then defining `_POSIX_SOURCE' as well has no effect.
  84. Likewise, if you define `_GNU_SOURCE', then defining either
  85. `_POSIX_SOURCE' or `_POSIX_C_SOURCE' or `_SVID_SOURCE' as well has no
  86. effect.
  87.  
  88.    Note, however, that the features of `_BSD_SOURCE' are not a subset of
  89. any of the other feature test macros supported.  This is because it
  90. defines BSD features that take precedence over the POSIX features that
  91. are requested by the other macros.  For this reason, defining
  92. `_BSD_SOURCE' in addition to the other feature test macros does have an
  93. effect: it causes the BSD features to take priority over the conflicting
  94. POSIX features.
  95.  
  96.